<?php

   $conn= mysql_connect("localhost","root","root") or die("Could not connect to MySQL");
   mysql_select_db("postit");
   if ($_REQUEST['cathegory']=="Tutte"){
      $q=mysql_query("SELECT DISTINCT(id),postit.name,author,DATE_FORMAT(segnalationDate,'%d-%m-%Y %H:%i') as segnalationDate,description,cathegory,ranking,valutationsNumber 
                   FROM  postit.postit,postit.user
		   WHERE postit.author=user.username AND postit.waypoint=".$_REQUEST['waypoint']." ORDER BY postit.cathegory,user.ranking desc;");}
   else  {
      $q=mysql_query("SELECT DISTINCT(id),postit.name,author,DATE_FORMAT(segnalationDate,'%d-%m-%Y %H:%i') as segnalationDate,description,cathegory,ranking,valutationsNumber 
                   FROM  postit.postit,postit.user
		   WHERE postit.author=user.username AND postit.waypoint=".$_REQUEST['waypoint']." AND postit.cathegory='".$_REQUEST['cathegory']."' ORDER BY user.ranking desc;");}
   while($e=mysql_fetch_assoc($q))
         $output[]=$e;

   print(json_encode($output));    
   mysql_close();

?>
